class Plant {
    constructor(name) {
        this.name = name;
    }
    grow() {
        console.log("这是第一个")
    }
}
class Apple extends Plant {
    constructor(name, flavour) {
        super(name, flavour)
        this.flavour = flavour;
    }
}
class Orange extends Plant {
    constructor(name, flavour) {
        super(name)
        this.flavour = flavour;
    }
}
/** 这是正常的new有特点 不耦合，依赖不强 */
new Apple()
new Orange()
/**
 * 这里的static是必须要用到的 简单工厂开闭原则,对修改关闭，对扩展开放
 *  */
class Factory {
   static create(type) {
        switch (type) {
            case "Apple":
                return new Apple("apple", "喜欢")
            case "Orange":
                return new Orange("orange", "不喜欢")
            default:
                throw new Error("不对了")
        }
    }
}

let apple = Factory.create("Apple");
console.log(apple.flavour)
